const MT_CREDIT = 1
const MT_GOV = 2
const MT_BANK = 3
const MT_GXS_MANAGER = 4
const MT_GXS_CORP = 5
// 银行端分基础档案和完整档案 2019.11.5
const MT_BANK_BASE = 6
const moduleMap = new Map([
  // 基本信息
  [
    'base',
    {
      show: [MT_CREDIT, MT_GOV, MT_BANK, MT_GXS_CORP, MT_GXS_MANAGER, MT_BANK_BASE],
      printHide: [],
    },
  ],
  // 资金需求
  [
    'funds',
    {
      show: [MT_CREDIT, MT_GOV, MT_BANK, MT_GXS_CORP, MT_GXS_MANAGER, MT_BANK_BASE],
      printHide: [],
    },
  ],
  // 历史沿革
  [
    'history',
    {
      show: [MT_BANK, MT_GXS_CORP, MT_CREDIT],
      printHide: [],
    },
  ],
  // 借款用途及还款计划
  [
    'plan',
    {
      show: [MT_BANK, MT_GXS_CORP, MT_CREDIT],
      printHide: [],
    },
  ],
  // 信贷八有指标
  [
    'target',
    {
      show: [MT_CREDIT, MT_GOV, MT_GXS_CORP, MT_GXS_MANAGER, MT_BANK_BASE, MT_BANK],
      printHide: [],
    },
  ],
  // 环保及准入信息
  [
    'env',
    {
      show: [MT_CREDIT, MT_GXS_CORP, MT_GOV],
      printHide: [],
    },
  ],
  // 工商信息、家庭主要成员
  [
    'emp',
    {
      show: [MT_CREDIT, MT_GOV, MT_BANK, MT_GXS_CORP, MT_GXS_MANAGER, MT_BANK_BASE],
      printHide: [],
    },
  ],
  // 产业信息
  [
    'product',
    {
      show: [MT_CREDIT, MT_GOV, MT_BANK, MT_GXS_CORP, MT_GXS_MANAGER, MT_BANK_BASE],
      printHide: [],
    },
  ],
  // 经营类分析
  [
    'business',
    {
      show: [MT_BANK, MT_CREDIT],
      printHide: [MT_GXS_CORP, MT_GXS_MANAGER],
    },
  ],
  // 生产要素
  [
    'produce',
    {
      show: [MT_CREDIT, MT_GOV, MT_BANK, MT_GXS_CORP, MT_GXS_MANAGER, MT_BANK_BASE],
      printHide: [],
    },
  ],
  // 保险信息
  [
    'insurance',
    {
      show: [MT_CREDIT, MT_GOV, MT_BANK, MT_GXS_CORP, MT_GXS_MANAGER, MT_BANK_BASE],
      printHide: [],
    },
  ],
  // 用电信息
  [
    'electricity',
    {
      show: [MT_CREDIT, MT_GOV, MT_BANK, MT_GXS_CORP, MT_GXS_MANAGER, MT_BANK_BASE],
      printHide: [],
    },
  ],
  // 信用信息
  [
    'credit',
    {
      show: [MT_CREDIT, MT_BANK],
      printHide: [MT_GXS_CORP, MT_GXS_MANAGER],
    },
  ],
  // 资产信息
  [
    'asset',
    {
      show: [MT_CREDIT, MT_BANK, MT_GXS_CORP],
      printHide: [],
    },
  ],
  // 银行意见
  [
    'bank_des',
    {
      show: [MT_BANK, MT_CREDIT],
      printHide: [MT_GXS_CORP, MT_GXS_MANAGER],
    },
  ],
  // 资金来源
  [
    'finance',
    {
      show: [MT_CREDIT, MT_GOV, MT_GXS_CORP, MT_GXS_MANAGER, MT_BANK_BASE],
      printHide: [],
    },
  ],
  // 法院涉诉情况
  [
    'litigation',
    {
      show: [MT_CREDIT, MT_BANK, MT_GXS_CORP],
      printHide: [],
    },
  ],
  // 贷后管理日志
  [
    'record',
    {
      show: [MT_CREDIT],
      printHide: [MT_GXS_CORP, MT_GXS_MANAGER],
    },
  ],
  // 还款记录
  [
    'repay',
    {
      show: [MT_CREDIT],
      printHide: [MT_GXS_CORP, MT_GXS_MANAGER],
    },
  ],
  // 担保费支付情况
  [
    'fee',
    {
      show: [MT_CREDIT],
      printHide: [MT_GXS_CORP, MT_GXS_MANAGER],
    },
  ],
  // 贷款信息
  [
    'load_info',
    {
      show: [MT_BANK, MT_CREDIT],
      printHide: [MT_GXS_CORP, MT_GXS_MANAGER],
    },
  ],
  // 反担保措施
  [
    'counter_guarantee',
    {
      show: [MT_CREDIT, MT_BANK, MT_GXS_CORP, MT_GXS_MANAGER],
      printHide: [],
    },
  ],
  // 复核意见
  [
    'res_option',
    {
      show: [MT_CREDIT, MT_BANK, MT_GXS_CORP, MT_GXS_MANAGER],
      printHide: [MT_GXS_CORP, MT_GXS_MANAGER],
    },
  ],
])

const moduleUserMap = new Map([
  ['org_gov_ny', MT_GOV],
  ['org_agr_leader', MT_BANK],
  [
    'org_supply_market',
    new Map([
      ['org_corp', MT_GXS_CORP],
      ['org_manager', MT_GXS_MANAGER],
    ]),
  ],
  [
    'org_credit',
    new Map([
      ['base', MT_BANK_BASE],
      ['intact', MT_CREDIT],
    ]),
  ],
  [
    'org_bank',
    new Map([
      ['base', MT_BANK_BASE],
      ['intact', MT_BANK],
    ]),
  ],
])

const getUserType = (org, job, fileType) => {
  const type = moduleUserMap.get(org)
  if (
    Object.prototype.toString.call(type) === '[object Map]' &&
    ['org_bank', 'org_credit'].includes(org)
  ) {
    return type.get(fileType)
  }
  if (Object.prototype.toString.call(type) === '[object Map]') {
    return type.get(job)
  }
  return type
}

// 查看与修改的模块一致
export const userViewMode = [2]

export const getModules = ({ org, job, viewMode, fileType }) => {
  const userType = getUserType(org, job, fileType)

  const show = []
  const printHide = []
  for (const [key, value] of moduleMap) {
    // show
    if (viewMode && !userViewMode.includes(userType) && value.show.includes(userType)) {
      show.push(key)
    } else if (value.show.includes(userType)) {
      show.push(key)
    }

    // printHide
    if (value.printHide.includes(userType)) {
      printHide.push(key)
    }
  }
  return { show, printHide }
}
